//
//  MineGoldView.swift
//  Box
//
//  Created by mn on 2025/4/3.
//

import UIKit
import SnapKit

class MineGoldView: UIView {
    
    private let backgroundImageView: UIImageView = {
        let imageView = UIImageView(image: UIImage.mineGoldBg)
        imageView.contentMode = .scaleToFill
        imageView.clipsToBounds = true
        imageView.isUserInteractionEnabled = true
        return imageView
    }()
    
    private let topLabel: UILabel = {
        let label = UILabel()
        label.textColor = .fromHex("#001C00")
        label.font = UIFont.boldSystemFont(ofSize: 15)
        label.text = "我的金币"
        return label
    }()
    
    private let topLabelIcon: UIImageView = {
        let imageView = UIImageView(image: UIImage.gold)
        imageView.contentMode = .scaleAspectFit
        return imageView
    }()
    
    let bottomLabel: UILabel = {
        let label = UILabel()
        label.textColor = .fromHex("#001C00")
        label.font = UIFont.systemFont(ofSize: 24,weight: .bold)
        label.text = "0.00"
        return label
    }()
    lazy var button: InsetBorderButton = {
        let button = InsetBorderButton(type: .custom)
        button.setTitle("立即充值", for: .normal)
        button.setTitleColor(.fromHex("#CAFE67"), for: .normal)
        button.layer.cornerRadius = 7.5
        button.titleLabel?.font = .systemFont(ofSize: 14)
        button.backgroundColor = .black
        button.borderColor = .fromHex("#CAFE67")
        return button
    }()
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupView()
    }
    
    required init?(coder: NSCoder) {
        super.init(coder: coder)
        setupView()
    }
    
    private func setupView() {
        addSubview(backgroundImageView)
        backgroundImageView.addSubview(topLabel)
        backgroundImageView.addSubview(topLabelIcon)
        backgroundImageView.addSubview(bottomLabel)
        backgroundImageView.addSubview(button)
        
        backgroundImageView.snp.makeConstraints { make in
            make.edges.equalTo(UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0))
        }
        
        topLabel.snp.makeConstraints { make in
            make.top.equalToSuperview().offset(11)
            make.left.equalToSuperview().offset(16+20)
        }
        
        topLabelIcon.snp.makeConstraints { make in
            make.left.equalTo(topLabel.snp.right).offset(7)
            make.centerY.equalTo(topLabel)
            make.width.height.equalTo(23)
        }
        
        bottomLabel.snp.makeConstraints { make in
            make.top.equalTo(topLabel.snp.bottom).offset(14.5)
            make.left.equalTo(topLabel.snp.left)
        }
        button.snp.makeConstraints { make in
            make.right.equalToSuperview().inset(20+17)
            make.bottom.equalToSuperview().inset(17)
            make.size.equalTo(CGSize(width: 81, height: 33))
        }
    }
    
    func configure(backgroundImage: UIImage?, topText: String, topIcon: UIImage?, bottomText: String) {
        backgroundImageView.image = backgroundImage
        topLabel.text = topText
        topLabelIcon.image = topIcon
        bottomLabel.text = bottomText
    }
}
